package com.ayoka.parenting.ui.coach.commentstudent;

import com.ayoka.parenting.R;
import com.ayoka.parenting.bean.BaseResponse;
import com.ayoka.parenting.bean.MeditationHistoryBean;
import com.ayoka.parenting.interf.SimpleRequestCallback;
import com.ayoka.parenting.mvp.BasePresenterImpl;
import com.jincp.common.utils.UIUtils;

/**
 * @ProjectName: MVPPlugin.
 * @ClassName: CommentStudentPresenter.
 * @Description: .
 * @Author: jincp.
 * @CreateDate: 2019/10/10 18:17.
 */
public class CommentStudentPresenter extends BasePresenterImpl<CommentStudentContract.View> implements CommentStudentContract.Presenter {

    private CommentStudentModel model;

    public CommentStudentPresenter() {
        model = new CommentStudentModel();
    }

    @Override
    public void getMeditationHistoryData(String recordId) {
        mView.get().showWaitDialog(UIUtils.getString(R.string.loading));
        model.getMeditationHistoryData(this, recordId, new SimpleRequestCallback<MeditationHistoryBean>() {
            @Override
            public void onSuccess(MeditationHistoryBean data) {
                if (!isAttached()) return;
                mView.get().hideWaitDialog();
                mView.get().configMeditationHistoryData(data);
            }

            @Override
            public void onFailure(int errCode, String errMsg) {
                if (!isAttached()) return;
                mView.get().hideWaitDialog();
                mView.get().showToast(errMsg);
            }
        });
    }

    @Override
    public void submitComment(String recordId, String commentContent) {
        mView.get().showWaitDialog(UIUtils.getString(R.string.loading));
        model.submitComment(this, recordId, commentContent, new SimpleRequestCallback<BaseResponse>() {
            @Override
            public void onSuccess(BaseResponse data) {
                if (!isAttached()) return;
                mView.get().hideWaitDialog();
                mView.get().onSubmitCommentCallback(true);
            }

            @Override
            public void onFailure(int errCode, String errMsg) {
                if (!isAttached()) return;
                mView.get().hideWaitDialog();
                mView.get().showToast(errMsg);
                mView.get().onSubmitCommentCallback(false);
            }
        });
    }
}
